<template>
  <div class="box-padding">
    <Row style="height: 40px">
      <Col span="9">
      <span>配置本层级风险调度岗</span>
      </Col>
      <Col span="3"
           :offset='11'
           v-show="control.add">
      <Button type="primary"
              @click="dispose()">配置风险调度岗</Button>
      </Col>
    </Row>

    <Table border
           :columns="columns"
           :data="data"></Table>

    <!-- <Modal v-model="modal2"
           width="360">
      <p slot="header"
         style="color:#333; text-align:center; border-bottom:none !important;">
        <span>删除提醒</span>
      </p>
      <div style="text-align:center;border:none !important;">
        确认要删除此项内容吗？
      </div>
      <div slot="footer"
           style="text-align:center;border:none !important;">
        <Button shape="circle"
                @click="modal2 = !modal2">取消</Button>
        <Button shape="circle"
                type="error"
                @click="removeClick">删除</Button>
      </div>
    </Modal> -->
  </div>
</template>

<script>
import { getUserInLocalstorage, getButtonInLocalstorage } from '@/libs/util'
export default {
  name: 'dispatch-post',
  data() {
    return {
      modal2: false,
      columns: [
        {
          title: '序号',
          align: 'center',
          render: (h, params) => {
            return h('span', params.index + 1)
          }
        },
        {
          title: '风险调度岗',
          align: 'center',
          key: 'name'
        },
        {
          title: '联系方式',
          align: 'center',
          key: 'tel'
        },
        {
          title: '所属部门',
          align: 'center',
          key: 'deptName'
        },
        {
          title: '职务',
          align: 'center',
          key: 'postName',
          tooltip: true
        },
        {
          title: '操作',
          align: 'center',
          render: (h, params) => {
            return h('div', [
              this.control.delete
                ? h(
                    'Button',
                    {
                      props: {
                        type: 'text',
                        size: 'small',
                        ghost: true
                      },
                      style: {
                        color: '#2d8cf0'
                      },
                      on: {
                        click: () => {
                          this.removeBox(params.row.id)
                        }
                      }
                    },
                    '删除'
                  )
                : ''
            ])
          }
        }
      ],
      data: [],
      total: 0,
      deleteIndex: '',
      deleteItem: {},
      control: {},
      userInfo: {}
    }
  },
  created() {
    this.userInfo = getUserInLocalstorage()
    this.buttonShow()
    this.getList()
  },
  methods: {
    // 职务列表
    getList() {
      // let type
      // if (this.userInfo.userInOrgType == 'ROOT_ENTERPRISE_USER') {
      //   type = 1
      // } else if (this.userInfo.userInOrgType == 'NOMAL_ENTERPRISE_USER') {
      //   type = 2
      // } else {
      //   type = 3
      // }
      // let params = {
      //   organizationId: this.userInfo.enterpriseId,
      //   organizationTypeId: type,
      //   projectTeamId: this.userInfo.projectTeamId
      // }
      this.$api.disPathch.getList().then(res => {
        if (res.code == 200) {
          this.data = res.data
        } else {
          this.$Message.warning(res.message)
        }
      })
    },
    // 删除
    // removeBox(id) {
    //   this.modal2 = !this.modal2
    //   this.removeClick(id)
    // },
    removeBox(id) {
      this.$api.disPathch.delete(id).then(resp => {
        if (resp.code == 200) {
          //this.modal2 = !this.modal2
          this.getList()
        } else {
          this.$Message.warning(resp.message)
          //this.modal2 = !this.modal2
        }
      })
    },
    //按钮权限
    buttonShow() {
      let buttonList = JSON.parse(localStorage.getItem('buttonList'))
      buttonList.map(val => {
        let key = Object.keys(val).toString()
        if (key == this.$route.name) {
          Object.values(val)[0].map(item => {
            if (item.code == 'P_0507_01') {
              this.control.add = true
            } else if (item.code == 'P_0507_02') {
              this.control.delete = true
            }
          })
        }
      })
    },
    dispose() {
      //配置调度岗
      const id = parseInt(Math.random() * 100000)
      let route = {
        name: 'dispatch-post-add',
        params: {
          id
        }
      }
      this.$router.push(route)
    }
  }
}
</script>

<style scope>
.page-div {
  padding-top: 20px;
  width: 100%;
  text-align: center;
}
</style>
